import { http } from "@/utils/request";
// 获取所有用户
export const getAllUsersAPI = (token: string) => {
  return http.get("/users", {
    headers: {
      Authorization: `Bearer ${token}`, // 在请求头中携带 token
    },
  });
};
// 添加用户
interface AddUserParams {
  username: string;
  password: string;
  roleId: number;
}
export const addUserAPI = (token: string, data: AddUserParams) => {
  return http.post("/users/create", data, {
    headers: { Authorization: `Bearer ${token}` },
  });
};

// 修改用户
interface UpdateUserParams {
  id: number;
  username: string;
  oldPassword: string;
  newPassword: string;
  roleId: number;
}
export const updateUserAPI = (token: string, data: UpdateUserParams) => {
  return http.put(`/users/${data.id}`, data, {
    headers: { Authorization: `Bearer ${token}` },
  });
};
// 删除用户
export const deleteUserAPI = (token: string, id: number) => {
  return http.delete(`/users/${id}`, {
    headers: { Authorization: `Bearer ${token}` },
  });
};
